// functions -------------------------------------------------------------------
function nowdate(){
  $("span#hktime").html("北京时间：<b>"+now.getDate()+ "日" +(now.getHours())+":"+(now.getMinutes())+":"+(now.getSeconds()+"</b>"));
  now.setTime(now.getTime() + 1000);
  setTimeout("nowdate()",1000);
}

var reflashTime = true;
function countdown(){
    if (timestap >= 0) {
      timediff = timestap;
      days = Math.floor(timediff / (60 * 60 * 24)); 
    	timediff -= days * (60 * 60 * 24);
    	hours = Math.floor(timediff / (60 * 60));
    	timediff -= hours * (60 * 60);
    	mins = Math.floor(timediff / (60));
    	timediff -= mins * (60);
    	secs = Math.floor(timediff);
        
      str = " || 距离截止下注时间还有 ";
      if (days > 0 ) str += "<b>" + days + "</b> 天 ";
      if (hours > 0) str += "<b>" + hours + "</b> 小时 ";
      if (mins > 0) str += "<b>" + mins + "</b> 分钟 ";
      str += "<b>" + secs + "</b> 秒 ";
      $("span#countdownstr").html(str);
      setTimeout("countdown()",1000)
      if($("select#reflashtime").val() != 0){$(this).chgMinData();} // reflash time
      timestap-=1;
      if (timestap==0) {
          //$().getAjaxDataAuto(_playtype, __roundID);
          $("input#btnReflash").click();
	    }
    } else {
        $("span#countdownstr").html("<font color=red><b>已经截止下注 !</b></font>");
        if(reflashTime){
          setTimeout("myNowPageReload()" , 120000);
          reflashTime = false;
        }
    }
}

function myNowPageReload(){
  window.location.reload();
}

// jQuery Functions ------------------------------------------------------------
$.fn.getAjaxDataAuto = function(playtype, _lotto_id){  
   // window.open('op.php?op=agent&fp=xmlBetTotal_sb&' + $("form#frmMenu").serialize());
   // return;  
 $.getJSON('op.php?op=agent&fp=xmlBetTotal_sb&' + $("form#frmMenu").serialize() ,function(ratedata){
      var dataLen = 0;
      var urlPre = "";
      var hrefStr = "";
      if(ratedata.errormsg != undefined){
        $("div#errormsg").addClass("error").text("No Rate data");
      }else{
          switch(playtype){
              case 'r1': show_r1(_lotto_id, playtype, ratedata, _myHeader); break;
              case 'r2': show_r2(_lotto_id, playtype, ratedata, _myHeader); break;
			  case 'r3': show_r3(_lotto_id, playtype, ratedata, _myHeader); break;
			  case 'r4': show_r4(_lotto_id, playtype, ratedata, _myHeader); break;
			  case 'r5': show_r5(_lotto_id, playtype, ratedata, _myHeader); break;
              default: show_default(); break; 
          }
          
          // set url
          $("span.span3da").click(function(){ $(this).setSpanAUrl(); });
          
          // set Btn Mim AND Plus
          $("#myDivTbl table td>input[class^=btn]").click(function(){
            $(this).setBtnMPUrl();
          });
          
          // show the menu bar for amount of each page
          $().showPgTotalAmount(ratedata.pgTotalAmountStr);

          // 可按号码快选之玩法
          var curPointStr = ",rnp,rc,";
          var playtypeTemp = "," + playtype + ",";
          if(curPointStr.indexOf(playtypeTemp) > -1){
             $("th.td6").css("cursor", "pointer").click(function(){
              var strTemp = $("input#iptQuick01Val").val();
              var addStr = $(this).text(); 
              if(strTemp == ""){ $("input#iptQuick01Val").val(addStr); }
              else{     
                var srcStrTemp = "," + strTemp + ",";
                var addStrTemp = "," + addStr + ",";
                if(srcStrTemp.indexOf(addStrTemp) < 0){ $("input#iptQuick01Val").val(strTemp + "," + addStr); }
              }  
              });
          }
          
          // can change again
          $("form#frmMenu input").add("form#frmMenu select").removeAttr("disabled");
          
          // show now online
          if(ratedata.onlinesum != undefined){
            $("span#online_sum").text(ratedata.onlinesum);
          }
          
          // change tr color
          //$().chgTrColor();
      }
  });
};

$.fn.chgMinData = function(){
  tempMin = parseInt($("span#reflashtimeMin").text());
  if(tempMin == 0){
    //$(this).getAjaxDataAuto();
    $("input#btnReflash").click();
    $("span#reflashtimeMin").text(myGlobalVal.reloadCK);
  }else if(!$("select#reflashtime").attr("disabled")){
    $("span#reflashtimeMin").text(tempMin - 1);
  }
};

$.fn.chgTitleColorBlue = function(){$(".td15").removeClass("td15").addClass("td3");};
$.fn.chgTitleColorGray = function(){$(".td3").removeClass("td3").addClass("td15");};


// show the total bar
$.fn.showPgTotalAmount = function(oArr){
  var oTemp = "";
  var sTnD = new Date();
  var sTn = Math.round(sTnD.getTime() / 1000);
  for(x in oArr){
    oTemp = $('span#spanPageAmount' + oArr[x].idx ); 
    oTemp.text(oArr[x].amu);
    if( (oArr[x].tn > 0) && ((sTn - oArr[x].tn) < 30) ){
      oTemp.css({"background-color":"#FFFF99"});
    }else{
      oTemp.css({"background-color":""});
    }
  }
};  
// show the n/m url link
$.fn.setSpanAUrl = function(){
  var myid = $(this).attr("id").substr(4);
  var betdataArr = myid.split("_");
  var dates = $("input:hidden#dates").val();
  var datee = $("input:hidden#datee").val();
  var gametype = $("input:hidden#gametype").val();
  var lid = $("input:hidden#lotto_id").val();
  var xyid = $("#xyid").val();
  var showUrl = '?op=agent&fp=betlist_3d&noback=1&bettype='+betdataArr[0]+'&subid=' + betdataArr[1] + '&num='+ betdataArr[2]+"&dates="+dates+"&datee="+datee+"&gametype="+gametype+"&lid="+lid+"&xyid="+xyid;  
  //window.open(showUrl,'_self','scrollbars=yes');
  var oObj = document.getElementById("divRateRecord");
  oObj.innerHTML = "<div class='bgClc_" + gametype + "' align=right><input type='button' value='&nbsp;X&nbsp;' onclick='javascript:closeDiv();' class='c4'></div><iframe src='" + showUrl + "' width='100%' height='100%'></iframe><br />"; 
  oObj.className = "showRateRecord";
};

$.fn.setBtnMPUrl = function(){
  if($('#btnReflash').attr('disabled') == true){
    alert('不可操作太快');
    return false;
  }
  var myid = $(this).attr("id").substr(3); 
  var betdataArr = myid.split("_");
  var betsubIdx = betdataArr[0] + "_" + betdataArr[1]
  $("tbody>tr>td>input[class^=btn]").attr("disabled","disabled");
  $("form#frmMenu input#actionBettype").val(betsubIdx);
  $("form#frmMenu input#actionNum").val(betdataArr[2]);
  $("form#frmMenu input#actionMP").val($(this).attr("id").substr(0,1));
  $("form#frmMenu input#addType").val("1");
  $("form#frmMenu input#method").val("0");
   // var actionUrl = '?op=subsidary&fp=xmlSetRateS_sb&'+ $("form#frmMenu").serialize(); 
   // window.open(actionUrl,'_blank');
   // return false;
  $.ajax({
    type: 'POST',
    url: '?op=subsidary&fp=xmlSetRateS_sb&pagename=0',
    dataType: 'json',
    data: $("form#frmMenu").serialize(),
    success: function(rdata){
      if(rdata.msg=="OK"){
         $("tbody>tr>td>input[class^=btn]").removeAttr("disabled");
         $("form#frmMenu input#btnReflash").click();
         
      }
    }
  });
};

// update rate
$.fn.setRateByXML = function(){
  if($('#btnReflash').attr('disabled') == true){
    alert('不可操作太快');
    return false;
  }
  $.ajax({
    type: 'POST',
    url: '?op=subsidary&fp=xmlSetRateS_sb',
    dataType: 'json',
    data: $("form#frmMenu").serialize(),
    success: function(rdata){
      if(rdata.msg=="OK"){
        $("form#frmMenu input#btnReflash").click();
      }else{
        alert('error');
      }
    }
  });
};

// -----------------------------------------------------------------------------
// print table functions
// -----------------------------------------------------------------------------
// 双面盘
function crt_2face_com(rdata, rtotaldata, rnum, bettype, subBettype, sTitle, showTitleArr, rowSpanN, tdNum){
  var winlostStr = "";
  var setSpanAUrl = "";
  var setBtnId = "";
  var idx = 0;          // 阵列index
  var tempI = 0;        // 1, 2 (大, 小)    
  var str = "";
  var strTitle = "";
  var oObj = "";
  var num = 0;
  var setBtnId = "";
  var nextI = -1;        // 可秀玩法
  var i = 0;
  var l = 0;
  var l2 = 0;
  var littletotal = 0;
  var classCount = 0;
  var titleTemp = '';
  var colTemp = '';
  var tempCount = 0;
  var j = 0;
  for(i = 0, l = rdata.length; i < l; i++ ){
    l2 = showTitleArr[i].length;
    for(j = 0; j < l2; j++){  // 双面
      tempCount++;
      oObj = rdata[i][j];
      num = oObj.numbers;
      winlostStr = ( oObj.winlost < 0 ) ? "#FF00FF" : "green" ;                                         // 输赢的颜色
      setSpanAUrl = "class=span3da id='url_" +  bettype[i] + "_" + subBettype[i] + "_" + oObj.numbers + "'"; // 笔数与金额的连结
      setBtnId = "b_"+  bettype[i] + "_" + subBettype[i] + "_" + oObj.numbers;
              
      str += "<th class=td6>" + showTitleArr[i][j] + "</th>";
      str += "<td id='td_r" + bettype[i] +  "_" + subBettype[i] + "_" + num + "' class='" + oObj.bgclass + "'>";
      str += "<input type=button class=btnmin value='-' id=m" + setBtnId + " />" + oObj.rate + "<input type=button class=btnplus value='&Phi;' id=p" + setBtnId + " /><br />";
      str += "<span " + setSpanAUrl + " >" + oObj.totalnum + "/" + oObj.amount + "</span>";
      str += "</td>";  
      str += "<td align=right><font color=" + winlostStr + ">" + oObj.winlost + "</font></td>";
      if(oObj.bgclass != "") classCount = "namount";
    }
  }
  if(tempCount < tdNum){
   for(i = 0; i < (tdNum - tempCount); i++){
    str += '<td></td><td></td><td></td>';
   }
  }
  // count little total
  for(i = 0, l = rtotaldata.length; i < l; i++){
    littletotal += rtotaldata[i].amount - 0;
  }
  
  strTitle += "<tr class='td2 bigBottom' align=center>";
  if(rowSpanN > 1){ strTitle += "<th class=td6 rowspan=" + rowSpanN + ">" + sTitle + "</th>"; }
  else if(rowSpanN == 1){ strTitle += "<th class=td6>" + sTitle + "</th>"; }
  strTitle += "<th class='span3dall " + classCount + "'>" + littletotal + "</th>";
  
  return strTitle + str;

}

// 定位,连码
function crt_1To21(rdata, rtotaldata, rnum, bettype, subBettype, sTitle, iNumTr,ItemArr){
  var str = "";
  var winlostStr = "";
  var setSpanAUrl = "";
  var setBtnId = "";
  var htmlTemp = '<tr class="td2">';
  var htmlTitle = '<th>项目</th><th>注单</th><th>输赢</th>';
  var trArr = new Array();
  var idx = 0;
  var dataLen = rdata.length;
  var i = 0;                
  for(i = 0; i < iNumTr; i++){ trArr[i] = '';} 
  var oObj = 0;              
  var showTitleN = Math.floor(dataLen / iNumTr);
  if((dataLen % iNumTr) > 0){showTitleN += 1; }           
  str += '<caption class="td0 bgClc_' + myGlobalVal.gametype  + '">' + sTitle + '</caption>';
  str += '<thead><tr class="td15">';
  for(i = 0; i < showTitleN; i++){
    str += htmlTitle;
  }
  str += '</tr></thead>';
  str += '<tbody align=center>';
  for(i = 0; i < dataLen; i++){
    idx = i % iNumTr;
    oObj = rdata[i];
    winlostStr = ( oObj.winlost < 0 ) ? "#FF00FF" : "green";
    setSpanAUrl = " class=span3da id='url_" +  bettype + "_" + subBettype + "_" + oObj.numbers + "'"; // 笔数与金额的连结
    setBtnId = "b_"+  bettype + "_" + subBettype + "_" + oObj.numbers;
    trArr[idx] += "<th class=td6>" + ItemArr[oObj.numbers] + "</th>";
    trArr[idx] += "<td class='" + oObj.bgclass + "'><input type=button class=btnmin value='-' id=m" + setBtnId + " />" + oObj.rate + "<input type=button class=btnplus value='&Phi;' id=p" + setBtnId + " /><br /><span " + setSpanAUrl + ">" + oObj.totalnum + "/" + oObj.amount + "</span></td>"; 
    //trArr[idx] += "<td></td>";
    trArr[idx] += "<td nowrap class='jsbo' align=right><font color=" + winlostStr + ">" + oObj.winlost + "</font></td>";
    //trArr[idx] += "<td class='rate_th2'>" +  + "</td>";
  }
  if(idx++ != iNumTr){
    for(i = idx; i < iNumTr; i++){
      trArr[i] += '<td></td><td></td><td></td>';
    }
  }
  str += htmlTemp + trArr.join('</tr><tr class=td2>') + '</tr>'; 
  return str;
}

// 热门100
function crt_rcNumGroup(bettype, rcObj, rcTitle){
  var rcTdArr = [[],[],[],[]];
  var rcTdIdx = 0;
  var strTbl = "";
  var rcNumGroupL = rcObj.length;
  strTbl += "<table class='tblMy3D' width='990' >";
  strTbl += "<caption class='bgImg_" + myGlobalVal.gametype + "'>" + rcTitle + " - 热门100号</caption>";
  for(i = 0; i < rcNumGroupL; i++){
    rcTdIdx = parseInt(i / 25);
    rcTdArr[rcTdIdx].push( rcObj[i].num + "<span style='padding-left:10px;' class=span3da id='url_" +  bettype + "_0_" + rcObj[i].num + "' >" + rcObj[i].tn + "/" + rcObj[i].amu + "</span>");
  }
  strTbl += "<tr>";
  for(i = 0; i < rcTdArr.length; i++){
    if(rcTdArr[i].length > 0){
      strTbl += "<td valign='top'>" + rcTdArr[i].join("<br />") + "</td>";
    }
  }
  strTbl += "</tr>";
  strTbl += "</table>";
  return strTbl;
}

// 增量 - 按钮 + -
function crt_divBtnAddVal(showAct){
  var str = "";
  var btnArr = [5, 4, 3, 2, 1, 0.5, 0.4, 0.3, 0.2, 0.1, 0.05, 0.02, 0.01, 0.005, 0.001];
  str += "<div id='divBtnAddVal'>";
  str += "<span class=btnchoice>";
  str += btnArr.join("</span><span class=btnchoice>"); 
  str += "</span>";
  if(showAct) { str += "　动作<input type='button' value='-' class='btnmin'><input type='button' value='&Phi;' class='btnplus'>"; }
  str += "</div>";
  return str;
}

// 大单提示表格
function crt_chkhint(){
  return "";
  var chkhintStr = "";
  var chksoundStr = "";
  if($().getCookie('chkhint3DCK' + myGlobalVal.gametype,'0') == '1'){ chkhintStr = " checked "; }
  if($().getCookie('chksound3DCK' + myGlobalVal.gametype ,'0') == '1'){ chksoundStr = " checked "; }
  
  var str = "";
  str += "<label><input type='checkbox' id='chkhint' " + chkhintStr + ">大单视窗提示(不分玩法)</label>";
  str += "　<label><input type='checkbox' id='chksound' "+ chksoundStr +">大单音效提示</label>　　";
  //if(myGlobalVal.btnSetConfFly){ str += "<input type='button' id='btnSetConfFly' value='启动走飞' disabled />"; }
  //else{ str += "<input type='button' id='btnSetConfFly' value='启动走飞' />"; }
  return str;
}

// @param divType
// 1 一般 单双 大小 合单双
// 2 色波  红蓝绿
// 3 四喜 福禄寿喜
// 4 头
// 5 尾
function crt_divBtnQuick01(){
  var str = "";
  var btnArr = [];
  btnArr[0] = ['单', '双', '大', '小', '合单', '合双'];
  btnArr[1] = ['红', '蓝', '绿'];
  btnArr[2] = ['福', '禄', '寿', '喜'];
  btnArr[3] = ['0', '1', '2'];
  btnArr[4] = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
    
  str += "<div id='divBtnQuick01'>快选";
  str += "<span class='btnchoice'>"
  str += btnArr[0].join("</span><span class='btnchoice'>");
  str += "</span>";
  
  str += "&nbsp;◎&nbsp;头";
  str += "<span class='btnchoice'>"
  str += btnArr[3].join("</span><span class='btnchoice'>");
  str += "</span>";
  
  str += "&nbsp;◎&nbsp;尾";
  str += "<span class='btnchoice'>"
  str += btnArr[4].join("</span><span class='btnchoice'>");
  str += "</span>";
  
  str += "&nbsp;◎&nbsp;色波";
  str += "<span class='btnchoice'>"
  str += btnArr[1].join("</span><span class='btnchoice'>");
  str += "</span>";
  
  str += "&nbsp;◎&nbsp;四喜";
  str += "<span class='btnchoice'>"
  str += btnArr[2].join("</span><span class='btnchoice'>");
  str += "</span>";
  
  str += "&nbsp;<input type='text' value='' id='iptQuick01Val' size='40' /><input type='button' id='btnClear' class='colorBtnGray' value='清除' onclick='javascript:ClearQuick01Val()'/>";
  str += "</div>";
  return str;  

}
// -----------------------------------------------------------------------------
// 按钮 function 
// -----------------------------------------------------------------------------

// 切换 subbid
function chgsubid(subid){
  var subidStr = subid.toString();
  $('form#frmMenu input#subid').val(subid);
  $("input#btnReflash").click();
}

// 切换 bid
function chgbid(bid){
  var bidStr = bid.toString();
  $('form#frmMenu input#bid').val(bid);
  $("input#btnReflash").click();
}

// 清除
function ClearQuick01Val(){
  $('#iptQuick01Val').val('');
}

// 取得号码
function getdivBtnQuickNum(typeIdx){
  switch(typeIdx){
    case 0 :  return "01,03,05,07,09,11,13,15,17,19"; break; 
    case 1 :  return "02,04,06,08,10,12,14,16,18,20"; break; 
    case 2 :  return "11,12,13,14,15,16,17,18,19,20"; break; 
    case 3 :  return "01,02,03,04,05,06,07,08,09,10"; break; 
    case 4 :  return "01,03,05,07,09,10,12,14,16,18"; break; 
    case 5 :  return "02,04,06,08,11,13,15,17,19,20"; break; 
    case 6 :  return "01,02,03,04,05,06,07,08,09"; break; 
    case 7 :  return "10,11,12,13,14,15,16,17,18,19"; break; 
    case 8 :  return "20,21"; break; 
    case 9 :  return "10,20"; break; 
    case 10 : return "01,11,21"; break; 
    case 11 : return "02,12"; break; 
    case 12 : return "03,13"; break; 
    case 13 : return "04,14"; break; 
    case 14 : return "05,15"; break; 
    case 15 : return "06,16"; break; 
    case 16 : return "07,17"; break; 
    case 17 : return "08,18"; break; 
    case 18 : return "09,19"; break; 
    case 19 : return "01,04,07,10,13,16,19"; break; 
    case 20 : return "02,05,08,11,14,17,20"; break; 
    case 21 : return "03,06,09,12,15,18,21"; break; 
    case 22 : return "01,02,03,04,05"; break; 
    case 23 : return "06,07,08,09,10"; break; 
    case 24 : return "11,12,13,14,15"; break; 
    case 25 : return "16,17,18,19,20"; break; 
  }
  return "";
  
}

// check number string 
function formatNumStr(sStr){
  var sStrArr = sStr.split(",");
  var i = 0;
  var l = sStrArr.length;
  for(i = 0; i < l; i++){
    if(sStrArr[i].length != 2 ){ sStrArr[i] = '0' + sStrArr[i];}
  }
  return sStrArr.join();
}


// -----------------------------------------------------------------------------
// 玩法呼叫的function 
// -----------------------------------------------------------------------------
  
// 主盘势    
function show_r1(_lotto_id, playtype, ratedata, myHeader){
  var strTbl = "<table class='tblMy3D' width='990' >";
  //strTbl += _myHeader;
  var showBetSubArr = {'01':'<img src="skin/1/img/ball/1.png" width="20px">',
  '02':'<img src="skin/1/img/ball/2.png" width="20px">',
  '03':'<img src="skin/1/img/ball/3.png" width="20px">',
  '04':'<img src="skin/1/img/ball/4.png" width="20px">',
  '05':'<img src="skin/1/img/ball/5.png" width="20px">',
  '06':'<img src="skin/1/img/ball/6.png" width="20px">'};
   var showBetSubArr2 = {'01':'<img src="skin/1/img/ball/7.jpg" width="20px">',
  '02':'<img src="skin/1/img/ball/8.jpg" width="20px">'};
  strTbl += crt_1To21(ratedata.r0_0, ratedata.r0_0total, "", 0, 0, '三军',3,showBetSubArr);
  strTbl += crt_1To21(ratedata.r1_0, ratedata.r1_0total, "", 1, 0, '',1,showBetSubArr2);
  strTbl += "</table>";
  
  //function crt_2face_com(rdata, rtotaldata, rnum, bettype, subBettype, sTitle, showTitleArr, rowSpanN, tdNum){
  $("#myDivTbl").html(strTbl);
}
function show_r2(_lotto_id, playtype, ratedata, myHeader){
  var strTbl = "<table class='tblMy3D' width='990' >";
  //strTbl += _myHeader;
  var showBetSubArr = {'01':'<img src="skin/1/img/ball/1.png" width="20px"><img src="skin/1/img/ball/1.png" width="20px">',
  '02':'<img src="skin/1/img/ball/2.png" width="20px"><img src="skin/1/img/ball/2.png" width="20px">',
  '03':'<img src="skin/1/img/ball/3.png" width="20px"><img src="skin/1/img/ball/3.png" width="20px">',
  '04':'<img src="skin/1/img/ball/4.png" width="20px"><img src="skin/1/img/ball/4.png" width="20px">',
  '05':'<img src="skin/1/img/ball/5.png" width="20px"><img src="skin/1/img/ball/5.png" width="20px">',
  '06':'<img src="skin/1/img/ball/6.png" width="20px"><img src="skin/1/img/ball/6.png" width="20px">'};
   var showBetSubArr2 = {'01':'<img src="skin/1/img/ball/9.jpg" width="40px">',
  '02':'<img src="skin/1/img/ball/10.jpg" width="40px">'};
  strTbl += crt_1To21(ratedata.r3_0, ratedata.r3_0total, "", 3, 0, '短牌',3,showBetSubArr);
  strTbl += crt_1To21(ratedata.r8_0, ratedata.r8_0total, "", 8, 0, '',1,showBetSubArr2);
  strTbl += "</table>";
  
  //function crt_2face_com(rdata, rtotaldata, rnum, bettype, subBettype, sTitle, showTitleArr, rowSpanN, tdNum){
  $("#myDivTbl").html(strTbl);
}

function show_r3(_lotto_id, playtype, ratedata, myHeader){
  var strTbl = "<table class='tblMy3D' width='990' >";
  var showBetSubArr = {'01':'<img src="skin/1/img/ball/1.png" width="20px"><img src="skin/1/img/ball/1.png" width="20px"><img src="skin/1/img/ball/1.png" width="20px">',
  '02':'<img src="skin/1/img/ball/2.png" width="20px"><img src="skin/1/img/ball/2.png" width="20px"><img src="skin/1/img/ball/2.png" width="20px">',
  '03':'<img src="skin/1/img/ball/3.png" width="20px"><img src="skin/1/img/ball/3.png" width="20px"><img src="skin/1/img/ball/3.png" width="20px">',
  '04':'<img src="skin/1/img/ball/4.png" width="20px"><img src="skin/1/img/ball/4.png" width="20px"><img src="skin/1/img/ball/4.png" width="20px">',
  '05':'<img src="skin/1/img/ball/5.png" width="20px"><img src="skin/1/img/ball/5.png" width="20px"><img src="skin/1/img/ball/5.png" width="20px">',
  '06':'<img src="skin/1/img/ball/6.png" width="20px"><img src="skin/1/img/ball/6.png" width="20px"><img src="skin/1/img/ball/6.png" width="20px">'};
   var showBetSubArr2 = {'01':'<img src="skin/1/img/ball/11.jpg" width="40px">'};
  strTbl += crt_1To21(ratedata.r4_0, ratedata.r4_0total, "", 4, 0, '豹子/全骰',3,showBetSubArr);
  strTbl += crt_1To21(ratedata.r5_0, ratedata.r5_0total, "", 5, 0, '',1,showBetSubArr2);
  strTbl += "</table>";
  
  //function crt_2face_com(rdata, rtotaldata, rnum, bettype, subBettype, sTitle, showTitleArr, rowSpanN, tdNum){
  $("#myDivTbl").html(strTbl);
}
function show_r4(_lotto_id, playtype, ratedata, myHeader){
  var strTbl = "<table class='tblMy3D' width='990' >";
  //strTbl += _myHeader;
  var showBetSubArr = {'01':'<img src="skin/1/img/ball/1.png" width="20px"><img src="skin/1/img/ball/2.png" width="20px">',
  '02':'<img src="skin/1/img/ball/1.png" width="20px"><img src="skin/1/img/ball/3.png" width="20px">',
  '03':'<img src="skin/1/img/ball/1.png" width="20px"><img src="skin/1/img/ball/4.png" width="20px">',
  '04':'<img src="skin/1/img/ball/1.png" width="20px"><img src="skin/1/img/ball/5.png" width="20px">',
  '05':'<img src="skin/1/img/ball/1.png" width="20px"><img src="skin/1/img/ball/6.png" width="20px">',
  '06':'<img src="skin/1/img/ball/2.png" width="20px"><img src="skin/1/img/ball/3.png" width="20px">',
  '07':'<img src="skin/1/img/ball/2.png" width="20px"><img src="skin/1/img/ball/4.png" width="20px">',
  '08':'<img src="skin/1/img/ball/2.png" width="20px"><img src="skin/1/img/ball/5.png" width="20px">',
  '09':'<img src="skin/1/img/ball/2.png" width="20px"><img src="skin/1/img/ball/6.png" width="20px">',
  '10':'<img src="skin/1/img/ball/3.png" width="20px"><img src="skin/1/img/ball/4.png" width="20px">',
  '11':'<img src="skin/1/img/ball/3.png" width="20px"><img src="skin/1/img/ball/5.png" width="20px">',
  '12':'<img src="skin/1/img/ball/3.png" width="20px"><img src="skin/1/img/ball/6.png" width="20px">',
  '13':'<img src="skin/1/img/ball/4.png" width="20px"><img src="skin/1/img/ball/5.png" width="20px">',
  '14':'<img src="skin/1/img/ball/4.png" width="20px"><img src="skin/1/img/ball/6.png" width="20px">',
  '15':'<img src="skin/1/img/ball/5.png" width="20px"><img src="skin/1/img/ball/6.png" width="20px">'};
   var showBetSubArr2 = {'01':'<img src="skin/1/img/ball/9.jpg" width="40px">',
  '02':'<img src="skin/1/img/ball/10.jpg" width="40px">'};
  strTbl += crt_1To21(ratedata.r6_0, ratedata.r6_0total, "", 6, 0, '短牌',3,showBetSubArr);
  strTbl += "</table>";
  
  //function crt_2face_com(rdata, rtotaldata, rnum, bettype, subBettype, sTitle, showTitleArr, rowSpanN, tdNum){
  $("#myDivTbl").html(strTbl);
}
function show_r5(_lotto_id, playtype, ratedata, myHeader){
  var strTbl = "<table class='tblMy3D' width='990' >";
  //strTbl += _myHeader;
  var showBetSubArr = {'01':'<img src="skin/1/img/ball/a4.png" width="40px">',
  '02':'<img src="skin/1/img/ball/a5.png" width="40px">',
  '03':'<img src="skin/1/img/ball/a6.png" width="40px">',
  '04':'<img src="skin/1/img/ball/a7.png" width="40px">',
  '05':'<img src="skin/1/img/ball/a8.png" width="40px">',
  '06':'<img src="skin/1/img/ball/a9.png" width="40px">',
  '07':'<img src="skin/1/img/ball/a10.png" width="40px">',
  '08':'<img src="skin/1/img/ball/a11.png" width="40px">',
  '09':'<img src="skin/1/img/ball/a12.png" width="40px">',
  '10':'<img src="skin/1/img/ball/a13.png" width="40px">',
  '11':'<img src="skin/1/img/ball/a14.png" width="40px">',
  '12':'<img src="skin/1/img/ball/a15.png" width="40px">',
  '13':'<img src="skin/1/img/ball/a16.png" width="40px">',
  '14':'<img src="skin/1/img/ball/a17.png" width="40px">'};
   var showBetSubArr2 = {'01':'<img src="skin/1/img/ball/9.jpg" width="40px">',
  '02':'<img src="skin/1/img/ball/10.jpg" width="40px">'};
  strTbl += crt_1To21(ratedata.r7_0, ratedata.r7_0total, "", 7,0, '总点数',3,showBetSubArr);
  strTbl += "</table>";
  
  //function crt_2face_com(rdata, rtotaldata, rnum, bettype, subBettype, sTitle, showTitleArr, rowSpanN, tdNum){
  $("#myDivTbl").html(strTbl);
}

function show_default(){
  $("#myDivTbl").html('页面建构中....');
}


// 全部      
function show_all(_lotto_id, playtype, ratedata){
  _playtype = playtype;
  var strTbl = "";
  $("#myDivTbl").html(strTbl);
}


// -----------------------------------------------------------------------------
// 按了玩法执行结果
// -----------------------------------------------------------------------------
function clickTitle(playtype){
  if(playtype == 'r1all'){
    showOnlinebetAll(myGlobalVal.gametype, myGlobalVal.lotto_id);
    return;  
  }
 $("#myDivNow").empty();
 $("#myDivTblTop").empty();
 $("#myDivTbl").html('<span class="bgClc_' + myGlobalVal.gametype + '" style="padding:10px; border:1px #926F4A dashed;">Loading.....(资料下载中...请稍后...)<img src="image/loading.gif" /></span>');
 _playtype = playtype;
 
 $("form#frmMenu input#playtypestr").val(playtype);
 $("form#frmMenu input#bid").val("");
 $("form#frmMenu #xyid").css("display", "");
 $("#noxystr").addClass("noneRateRecord");
 // -- $("form#frmMenu input#subid").val("0");
 
 // 切换快选画面
// 切换快选画面
 var str = "<table width='990' class='table0' cellPadding=5>";
  str += "<tr class=td2><td align=center>" + crt_chkhint() + "</td><td align=right>" + crt_divBtnAddVal(false) + "</td></tr>";
  str += "</table>";
  $("#myDivNow").html(str);
 
 // button of add value -- over page
 $("#divBtnAddVal span").click(function(){
   var addVal = $(this).text();
   $("input#addVal").val(addVal);
   $("#divBtnAddVal span").removeClass("btnchoiced").addClass("btnchoice");
   $(this).addClass("btnchoiced");
   $().setCookie('btnAddVal3DCK' +playtype ,$(this).index());
 });
 
 var btnAddVal3DCK = $().getCookie('btnAddVal3DCK' + playtype,12);
 $("#divBtnAddVal span:eq(" + btnAddVal3DCK + ")").click();
 
 $("th.cbig").removeClass('cbig');
 $("th#myThBar" + playtype).addClass('cbig');
 
 // big bet remark  -- over page 
  
 
 // 切换快选画面
 //var str = "<table width='990' class='table0' cellPadding=5></table>";
 //switch(playtype){
 //   default : $("#myDivNow").html('预留区块'); break;
 //}
 
 $("input#btnReflash").click();
  
//   $("input:checkbox#chkhint").click(function(){
//     if($(this).attr("checked") == true){
//       $().setCookie('chkhint3DCK' + myGlobalVal.gametype,'1');
//       $().showTheBigBet('start');
//     }else{
//       $().showTheBigBet('stop');
//       $().setCookie('chkhint3DCK' + myGlobalVal.gametype,'0');
//     }
//   }); 
  
//   // big bet music remark -- over page
//   $("input:checkbox#chksound").click(function(){
//     if($(this).attr("checked") == true){
//       $().setCookie('chksound3DCK' + myGlobalVal.gametype,'1');
//     }else{
//       $().setCookie('chksound3DCK' + myGlobalVal.gametype,'0');
//     }
//   });
  
 
 
}



// -----------------------------------------------------------------------------
// for now page
// -----------------------------------------------------------------------------

$(function(){
  
  // the default value
  var reloadCK = $().getCookie('reflashtime3DCK',0);  
  var ratemodCK = $().getCookie('ratemod3DCK',0); 
  var diskCK = $().getCookie("disk3DCK",0);
  var splitCK = $().getCookie("split3DCK",0);
  var orderCK = $().getCookie("order3DCK",0);
  
  $("form#frmMenu select#reflashtime").val([reloadCK]);
  $("form#frmMenu select#ratemod").val([ratemodCK]);
  $("form#frmMenu select#disk").val([diskCK]);
  $("form#frmMenu select#split").val([splitCK]);   
  $("form#frmMenu select#order").val([orderCK]);
  
  nowdate();
  countdown();
  //$(this).getAjaxDataAuto(_playtype, __roundID);
  // change color when chang the split
  if($("form#frmMenu select#split").val()==1){
    $().chgTitleColorBlue();
  }
  
  // reflash data
  $("form#frmMenu select").not("#reflashtime").change(function(){
    //$(this).getAjaxDataAuto(_playtype, __roundID);
    //$("form#frmMenu input").add("form#frmMenu select").attr("disabled","true");
    $().setCookie($(this).attr("id")+"3DCK",$(this).val());
    $("input#btnReflash").click();
  });
  
  // change color when change the split
  $("select#split").change(function(){
    if($(this).val()==0){
      $().chgTitleColorGray();
    }else{
      $().chgTitleColorBlue();
    }
  });
  
  // reflash the time 
  $("select#reflashtime").change(function(){
    $().setCookie('reflashtime3DCK',$(this).val());
    $("span#reflashtimeMin").text($(this).val());
      if($(this).val() > 0){setTimeout(function(){
        $().chgMinData();
      }, 1000);}  
  });
  
    // raterecord -- over page
  $("input:button#btnRateRecord").click(function(){
    showRateRecordPage(myGlobalVal.gametype, myGlobalVal.open)  
  });  
  
  // button of reload, just reflash rates instade of reload all page
  $("input#btnReflash").click(function(){
    if($("form#frmMenu input:eq(0)").attr("disabled")){ return false; }
    $("span#reflashtimeMin").text(myGlobalVal.reloadCK);
    $(this).getAjaxDataAuto(_playtype, __roundID);
    $("form#frmMenu input").add("form#frmMenu select").attr("disabled","true");
  });
  
  clickTitle(myGlobalVal.playtypestr);
});